/* 分页路由
 * @Author: Leil 
 * @Date: 2018-09-05 22:27:08 
 * @Last Modified by: Leil
 * @Last Modified time: 2018-09-06 17:09:39
 */
const pageService = require('../service/pageService')
const postService = require('../service/postService')
module.exports = function(app) {
    app.get("/api/getPageNum", async (req, res) => {
        // console.log("getPageNum................")
        let data
        await pageService.getPageNum()
            .then(res => {
                data = {pageNum: res}
            })
        res.send(data)
        return
    })

    app.get("/api/getPostsByPage/:currentPage", async (req, res) => {
        let currentPage = req.params.currentPage
        let data
        await pageService.getPostsByPage(currentPage)
                .then(posts => {
                    data = posts
                })
        res.send(data)
        return
    })

    app.get("/api/getPostById/:postId", async (req, res) => {
        let postId = req.params.postId
        let data
        await postService.getPostById(postId)
                .then(post => {
                    data = post
                })
                .catch(error => {
                    console.log(error)
                })
        console.log(data)
        res.send(data)
        return
    })
}